package com.tianyang.yukuaifu.module.dialog;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.tianyang.yukuaifu.R;
import com.tianyang.yukuaifu.module.dialog.interfaces.TwoBtnClickListener;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Description：
 */
public class RemindDialog extends Dialog {
    @BindView(R.id.tvTitle)
    TextView titleTv;
    @BindView(R.id.tvContent)
    TextView contentTv;
    @BindView(R.id.cancel)
    TextView cancelTv;
    @BindView(R.id.sure)
    TextView comfirmTv;

    private String title, content, cancel, comfirm;

    private boolean cancelable = true;

    private TwoBtnClickListener clickListener;

    public RemindDialog title(String title) {
        this.title = title;
        return this;
    }

    public RemindDialog content(String content) {
        this.content = content;
        return this;
    }

    public RemindDialog cancel(String cancel) {
        this.cancel = cancel;
        return this;
    }

    public RemindDialog comfirm(String comfirm) {
        this.comfirm = comfirm;
        return this;
    }

    public RemindDialog listener(TwoBtnClickListener clickListener) {
        this.clickListener = clickListener;
        return this;
    }

    public RemindDialog cancelable(boolean cancelable) {
        this.cancelable = cancelable;
        setCancelable(cancelable);
        return this;
    }

    public RemindDialog(Context context) {
        super(context, R.style.dialog_normal);
        setContentView(R.layout.dialog_remind);
        ButterKnife.bind(this);
        setCancelable(cancelable);
    }

    @Override
    public void onAttachedToWindow() {
        if (!TextUtils.isEmpty(title)) {
            titleTv.setText(title);
        }
        if (!TextUtils.isEmpty(content)) {
            contentTv.setVisibility(View.VISIBLE);
            contentTv.setText(content);
        } else {
            contentTv.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(cancel)) {
            cancelTv.setText(cancel);
        }
        if (!TextUtils.isEmpty(comfirm)) {
            comfirmTv.setText(comfirm);
        }
    }

    @OnClick({R.id.sure, R.id.cancel})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.sure:
                if (clickListener != null) {
                    clickListener.onRightClick();
                }
                dismiss();
                break;
            case R.id.cancel:
                if (clickListener != null) {
                    clickListener.onLeftClick();
                }
                dismiss();
                break;
        }
    }
}
